/**    
 * @{#} SimpleArrayAdapter.java Create on 2014-6-9 下午7:28:43    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import cn.skinapp.R;

import com.evan.common.widget.PinnedSectionListView.PinnedSectionListAdapter;
import com.smiier.skin.utils.CommonUtility;
import com.smiier.skin.vo.SectionRow;

public class BuweiAdapter extends BaseAdapter implements
		PinnedSectionListAdapter {

	private ArrayList<SectionRow> items;

	View[] views;
	LayoutInflater inflater;

	public BuweiAdapter(Context context, ArrayList<SectionRow> items) {
		this.items = items;
		views = new View[items.size()];
		inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = views[position];
		if (!CommonUtility.isNull(convertView)) {
			return convertView;
		}
		SectionRow row = (SectionRow) getItem(position);

		if (row.type == SectionRow.SECTION) {
			convertView = inflater.inflate(R.layout.item_listview_head, null);
		} else {
			convertView = inflater.inflate(R.layout.item_buwei, null);
			CheckBox checkBox = (CheckBox) convertView
					.findViewById(R.id.check_buwei);
			checkBox.setTag(row);
			convertView.setTag(checkBox);
		}
		TextView text = (TextView) convertView.findViewById(R.id.text_content);
		text.setText(row.text);
		return convertView;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public int getItemViewType(int position) {
		return ((SectionRow) getItem(position)).type;
	}

	@Override
	public boolean isItemViewTypePinned(int viewType) {
		return viewType == SectionRow.SECTION;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
